<template>
  <div class="login-container">
    <el-form :model="loginForm" class="login-form">
      <el-form-item>
        <el-input v-model="loginForm.username" placeholder="Username"></el-input>
      </el-form-item>
      <el-form-item>
        <el-input type="password" v-model="loginForm.password" placeholder="Password"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" style="width:100%;margin-bottom:30px;" @click.native.prevent="handleLogin">提交</el-button>
        <!-- <el-button @click="resetForm('ruleForm')">重置</el-button> -->
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: "Login",
  //data: function(){}的便利写法
  data() {
    return {
      loginForm: {
        username: "",
        password: "",
      },
    };
  },
  methods: {
    handleLogin() {
      //user/login = user模块下的login action
      this.$store
        .dispatch("user/login", this.loginForm)
        .then(() => {
          this.$router.push({ path: "/dashboard" });
        })
        .catch((error) => {
          alert(error);
        });
    },
  },
};
</script>

<style  scoped>
.login-container {
  min-height: 100%; /* 没有这个的话页面的高度就是元素撑开div的高度，是固定的。有了这个就是动态高度，永远是100% */
  width: 100%;
  background-color: #2d3a4b;
  overflow: hidden;
}

.login-form {
  position: relative;
  width: 520px;
  max-width: 100%;
  padding: 160px 35px 0;
  margin: 0 auto;
  overflow: hidden;
}
</style>